int ledPin =  13;          // LED connected to digital pin 13
int delayDot = 200;             // How long the LED will remain lit for a "dot"
int delayDash = 500;            // How long the LED will remain lit for a "dash"
int delayLetter = 250;      // How long to turn off LED between letters
int delayWord = 500;        // How long to turn off LED between words


void setup() {                
  Serial.begin(9600);
  pinMode(ledPin, OUTPUT);     
}

void loop() {
  print_morse_code("h");
  print_morse_code("e");
  print_morse_code("l");
  print_morse_code("l");
  print_morse_code("o");
  print_space(1);
  print_morse_code("w");
  print_morse_code("o");
  print_morse_code("r");
  print_morse_code("l");
  print_morse_code("d");
  delay(1000);
}

// Convert letters to to morse code via LED and Serial echos 
void print_morse_code(char* letter) {
  // Hello 
  // ****  *  *-**  *-**  ---
  
  // World
  // *--  ---  *-*  *-**  -**
  
  if(letter=="h") {
      Serial.println("****");
      print_dot();
      print_dot();
      print_dot();
      print_dot(); 
 
  } else if (letter=="e") {     
      Serial.println("*");
      print_dot();
      
  } else if (letter=="l") { 
      Serial.println("*-**");
      print_dot();
      print_dash();
      print_dash();
      print_dash();

  } else if (letter=="o") {      
      Serial.println("---");
      print_dash();
      print_dash();
      print_dash();
      
  } else if (letter=="w") {
      Serial.println("*--");
      print_dot();
      print_dash();
      print_dash();
      
  } else if (letter=="r") { 
      Serial.println("*-*");
      print_dot();
      print_dash();
      print_dot();
      
  } else if (letter=="d") {
      Serial.println("-**");
      print_dash();
      print_dot();
      print_dot();
  }
  
  print_space(0);
}


void print_dot() {
  digitalWrite(ledPin, HIGH);   // set the LED on
  delay(delayDot);                  // wait for a second  
}

void print_dash() {
  digitalWrite(ledPin, HIGH);   // set the LED on
  delay(delayDot);                  // wait for a second
  
}

// Turn off LED
// 0 = Letter
// 1 = Word
void print_space(byte len) {
  digitalWrite(ledPin, LOW); // set LED off
  if(len==1) {
      delay(delayWord);
  } else {
      delay(delayLetter);
  }  
}

